//// Game Thread 
//// author: MV
package com.liquidcode.cellular;

import javax.microedition.khronos.opengles.GL10;

import android.os.Handler;
import android.os.SystemClock;
import android.view.SurfaceHolder;


import entities.CPlayer;

class GameThread extends Thread {
	private SurfaceHolder _holder;
	private GLSurface _renderView;
	public boolean running = false;
	private float secondsDelta;
	private float prevTime;
	public boolean shutdown = false;

	GameThread() {

	}

	@Override
	public void run() {
		super.run();

		while (running) {
			// do quick time calculations
			float currTime = SystemClock.uptimeMillis();
			float elapsed = (float) (currTime - prevTime) / 1000.0f;
			elapsed = elapsed * GameInfo.getInstance().GameStep;
			if (elapsed > 0.1f)
				elapsed = 0.1f;

			prevTime = currTime;

			if( GameInfo.getInstance().GameInitialized )
			{
				// Update Collisions
				CCollisionManager.getInstance().UpdateCollisions(elapsed);
				// update the camera 
				CCamera.getInstance().Update(elapsed);
				// update the map 
				CMapManager.getInstance().Update(elapsed);
				// Update enemies 
				CEnemyManager.getInstance().Update(elapsed);
				// update bullet manager
				CBulletManager.getInstance().Update(elapsed);
				// Update the player 
				CPlayer.getInstance().Update(elapsed);
				// update the InputManager (for drawing)
				//CInputManager.getInstance().Update(elapsed);
				CAttackManager.getInstance().UpdateShootInterval(elapsed);
				CTrailManager.getInstance().Update(elapsed);
			}
		}

	}
}